﻿




CREATE Function dbo.f_PosCreditCount
(@LoanID int,@AccType char(1) = '',@Pulled bit )
RETURNS int WITH SCHEMABINDING BEGIN

DECLARE @Ret int

IF @Pulled <> 1 RETURN dbo.RegistryValue('DefaultRuleValue')

IF ISNULL(@AccType,'') = ''
	SELECT @Ret = count(*)
	FROM dbo.v_TradeReferences
	WHERE LoanID = @LoanID AND Status = 1 AND (AccountState = 1)
ELSE
	SELECT @Ret = count(*)
	FROM dbo.v_TradeReferences
	WHERE LoanID = @LoanID AND AccType=@AccType AND Status = 1 AND (AccountState = 1)

RETURN  @Ret
END






